'use strict';

const Sequelize = require('sequelize');
var sequelize = new Sequelize('demo', 'cdb_outerroot', 'DDLNagijkQ3x', {
    host: '584cc92b380ff.gz.cdb.myqcloud.com',
    port: 16881,
    dialect: 'mysql',
    pool: {
        max: 5,
        min: 0,
        idle: 10000
    }
});

sequelize
    .authenticate()
    .then(function(err) {
        console.log('Connection has been established successfully.');
    })
    .catch(function(err) {
        console.log('Unable to connect to the database:', err);
    });

var User = sequelize.define('user', {
    firstName: {
        type: Sequelize.STRING
    },
    lastName: {
        type: Sequelize.STRING
    }
});

// force: true will drop the table if it already exists
User.sync({ force: false }).then(function() {
    // Table created
    return User.create({
        firstName: 'John',
        lastName: 'Hancock'
    });
});